package leetcode.erfen;

public class Test4 {
    public static void main(String[] args) {
        char[] letters = {'b', 'c', 'f', 'j'};
        char a = nextGreatestLetter(letters, 'd');
        System.out.println(a);
    }

    public static char nextGreatestLetter(char[] letters, char target) {
        int left = 0, right = letters.length - 1, mid;
        if (target > letters[right]) {
            return letters[0];
        }
        while (left <= right) {
            mid = (right + left) / 2;
            if (letters[mid] > target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return letters[left];
    }
}
